<?php
namespace App\DataBase;


use App\Exception\SqlException;

class PDOStatement extends \PDOStatement
{
    /**
     * @var PDO
     */
    protected $pdo;

    /**
     * @param PDO $pdo
     */
    protected function __construct($pdo)
    {
        $this->pdo = $pdo;
    }

    public function execute($input_parameters = NULL)
    {
        $result = parent::execute($input_parameters);

        if (!$result) {
            $error_info = parent::errorInfo();
            if (parent::errorCode() !== '00000') {
                throw new SqlException($this->pdo->getName() . ' | ' . $this->pdo->config['dsn'] . ' | ' . $this->queryString . ' | ' . join(' | ', $error_info), parent::errorCode());
            }
        }

        return $result;
    }
}